package com.libs.xxf.simple.textactivity

import android.annotation.SuppressLint
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.MotionEvent
import com.libs.xxf.simple.R
import com.tools.xxf.ijklib.common.MediaController
import com.tools.xxf.ijklib.common.PlayerManager
import com.tools.xxf.ijklib.media.IjkVideoView

class IjkDemo : AppCompatActivity()
              , PlayerManager.PlayerStateListener  {
    private val URL = "http://119.146.223.64:8000/group1/M00/00/00/3QTfZVnx3dWAbCVLBi2GN6UgtsY735.flv"

    private val mPlayer: IjkVideoView?
        get() {
            val mPlayer = findViewById<IjkVideoView>(R.id.player)
            return mPlayer
        }

    private val mController: MediaController?
        get() {
            val mController = findViewById<MediaController>(R.id.controller)
            return mController
        }

    private val playerManager: PlayerManager
        get() {
            val player = PlayerManager(this, mPlayer)
            return player
        }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_ijk_demo)

        mPlayer?.setMediaController(mController)
        playerManager.setScaleType(PlayerManager.SCALETYPE_FILLPARENT)
        playerManager.setPlayerStateListener(this)
        playerManager.play(URL)
    }

    override fun onComplete() {
        //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onError() {
        //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onLoading() {
        //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onPlay() {
        //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onBack() {
        //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onPrepared() {
       // TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        return playerManager.onTouchEvent(event)
    }
}
